<?php
$dt = new DataTable(constant('DB_TABLE_EPAPER_SEND_QUEUE'));
$act = isset($_REQUEST['act'])?$_REQUEST['act']:'';
if ( $act == 'set_pause') {
	$update_data = array('id'=>intval($_REQUEST['id']), 'status'=>'pause');
	$dt->save($update_data);
}
else if (  $act == 'set_wait' ){
	$update_data = array('id'=>intval($_REQUEST['id']), 'status'=>'wait_send');
	$dt->save($update_data);
}
else if (  $act == 'delete' ) {
	$row = $dt->remove($_REQUEST['id']);
}
$condition = "`status`='sent'";

$page = isset($_REQUEST['page'])?$_REQUEST['page']:1;
$page_size = isset($_REQUEST['page_size'])?$_REQUEST['page_size']:10;
$offset = $page_size * ( $page - 1);
$GLOBALS['PAGE_LIST_DATA'] = $dt->get_list($condition, array('-send_datetime','-id'), $page_size, $offset);
$total_row =  $dt->get_count($condition);
$GLOBALS['PAGE_LIST_TOTAL_PAGE'] = ceil($total_row/$page_size);
$GLOBALS['PAGE_LIST_PAGE'] = $page;
$_REQUEST['page'] = $page;

$dt = new DataTable(constant('DB_TABLE_EPAPER_CONTENT'));
foreach($GLOBALS['PAGE_LIST_DATA'] as $index=>$row)
{
	$epaper_row = $dt->get($row['epaper_id']);
	if ( $epaper_row ) {
	$GLOBALS['PAGE_LIST_DATA'][$index]['epaper_subject'] = $epaper_row['subject'];
	}
}
?>